package data;

import java.util.Date;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class Payment extends AbstractData{
	private long id = -1;
	private long hotelId;
	private String payMode;
	private PayType payType;
	private String payTypeString;
	private double amount;
	private long creditCardId;
	private String ccNo;
	private String ccNo2;
	private String description;
	private boolean avaliable;
	private Date payDate;
	private Payment parentPayment;
	private String parentPaymentString;
	private long folioId;
	private Reservation resId;
	private String resIdString;
	private long counterId;
	
	public Reservation getResId() {
		if (resId == null && !(resIdString == null || resIdString.isEmpty())) {
			Reservation c = new Reservation(Long.parseLong(resIdString));	
			c.LoadData();
			resId = c;
		}
		return resId;
	}
	public void setResId(Reservation resId) {
		this.resIdString = String.format("%d", resId.getId());
		this.resId = resId;
	}
	
	public String getResIdString() {
		return resIdString;
	}
	public void setResIdString(String resIdString) {
		this.resIdString = resIdString;
	}
	public Payment(){
		
	}
	public Payment(long id) {
		this.id = id;
	}

	public long getHotelId() {
		return hotelId;
	}

	public void setHotelId(long hotelId) {
		this.hotelId = hotelId;
	}

	public String getPayMode() {
		return payMode;
	}

	public void setPayMode(String payMode) {
		this.payMode = payMode;
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}

	public String getCcNo() {
		return ccNo;
	}

	public void setCcNo(String ccNo) {
		this.ccNo = ccNo;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean isAvaliable() {
		return avaliable;
	}

	public void setAvaliable(boolean avaliable) {
		this.avaliable = avaliable;
	}

	public Date getPayDate() {
		return payDate;
	}

	public void setPayDate(Date payDate) {
		this.payDate = payDate;
	}

	public long getId() {
		return id;
	}

	public PayType getPayType() {
		if (payType == null && !(payTypeString == null || payTypeString.isEmpty())) {
			PayType c = new PayType(Long.parseLong(payTypeString));	
			c.LoadData();
			payType = c;
		}
		return payType;
	}

	public void setPayType(PayType payType) {
		this.payTypeString = String.format("%d", payType.getId());
		this.payType = payType;
	}
	
	public Payment getParentPayment() {	
		if (parentPayment == null && !(parentPaymentString == null || parentPaymentString.isEmpty())) {
			Payment c = new Payment(Long.parseLong(parentPaymentString));	
			c.LoadData();
			parentPayment = c;
		}
		return parentPayment;
	}
	public void setParentPayment(Payment parentPayment) {
		this.parentPaymentString = String.format("%d", parentPayment.getId());
		this.parentPayment = parentPayment;
	}
	public String getParentPaymentString() {
		return parentPaymentString;
	}
	public void setParentPaymentString(String parentPaymentString) {
		this.parentPaymentString = parentPaymentString;
	}
	
	public void setId(long id) {
		this.id = id;
	}

	public void setPayTypeString(String payTypeString) {
		this.payTypeString = payTypeString;
	}

	
	public String getCcNo2() {
		return ccNo2;
	}
	public void setCcNo2(String ccNo2) {
		this.ccNo2 = ccNo2;
	}
	public String getPayTypeString() {
		return payTypeString;
	}
	
	
	public long getFolioId() {
		return folioId;
	}
	public void setFolioId(long folioId) {
		this.folioId = folioId;
	}
	
	public long getCounterId() {
		return counterId;
	}
	public void setCounterId(long counterId) {
		this.counterId = counterId;
	}
	public long getCreditCardId() {
		return creditCardId;
	}
	public void setCreditCardId(long creditCardId) {
		this.creditCardId = creditCardId;
	}
	
	@Override
	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.Payment);
		else
			item = new Entity(this.key);

		item.setProperty("HotelId", this.hotelId);
		item.setProperty("payMode", this.payMode);		
		item.setProperty("payType", this.payTypeString);
		item.setProperty("amount", this.amount);
		item.setProperty("ccNo", this.ccNo);
		item.setProperty("ccNo2", this.ccNo2);
		item.setProperty("payDate", this.payDate);
		item.setProperty("Description", this.description);
		item.setProperty("Avaliable", this.avaliable);	
		item.setProperty("folioId", this.folioId);
		item.setProperty("ParentPayment", this.parentPaymentString);
		item.setProperty("resId", this.resIdString);
		item.setProperty("counterId", this.counterId);
		item.setProperty("creditCardId",this.creditCardId);
		return item;
	}

	@Override
	public void setEntity(Entity entity) {
		this.id = entity.getKey().getId();
		this.hotelId = (Long) entity.getProperty("HotelId");
		this.payMode = (String) entity.getProperty("payMode");
		this.payTypeString = (String) entity.getProperty("payType");
		this.amount = (Double) entity.getProperty("amount");
		this.ccNo = (String) entity.getProperty("ccNo");
		this.ccNo2 = (String) entity.getProperty("ccNo2");
		this.description = (String) entity.getProperty("Description");
		this.avaliable = (Boolean) entity.getProperty("Avaliable");
		this.payDate = (Date) entity.getProperty("payDate");
		this.folioId = (Long) entity.getProperty("folioId");
		this.parentPaymentString = (String) entity.getProperty("ParentPayment");
		this.resIdString = (String) entity.getProperty("resId");
		this.counterId =(Long) entity.getProperty("counterId");
		this.creditCardId =(Long) entity.getProperty("creditCardId");
		this.key = entity.getKey();
	}
	
	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.Payment, this.id);
			setEntity(entity);
		}
	}

}
